package com.egao.api.controller.gps;


import com.egao.common.core.damon.results.PageResult2;
import com.egao.common.core.web.BaseController;
import com.egao.common.core.web.JsonResult;
import com.egao.common.system.service.OperRecordService;
import com.egao.gps.ZjxlGps;
import com.egao.gps.entity.CarPosition;
import com.egao.gps.service.CarPositionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

//import com.egao.orderB.entity.Bill;
//import com.egao.orderB.service.BillService;

/**
 * api登录相关接口
 * Created by wangfan on 2019-05-29 下午 3:43.
 * http://localhost/swagger-ui.html
 */
//mongodb
//https://www.cnblogs.com/yinjihuan/p/10766652.html
@RequestMapping("/api/gps")
@RestController
@Api(value = "地图模块",tags = {"地图模块"})
public class ApiGpsController extends BaseController {
    @Autowired
    private OperRecordService operRecordService;
    @Autowired
    private CarPositionService carPositionService;

    /**
     * 地图模块列表
     */
    @PreAuthorize("hasAuthority('gps:gps:list')")
    @PostMapping("/listPage")
    @ApiOperation(value = "地图模块列表",notes = "" +
            "limit:每页显示几行 必填\n" +
            "page:第几页 必填\n" +
            "carNo 车牌\n" +
            "返回的字段:\n" +
            "id; id\n" +
            "vno 车牌\n" +
            "driver 司机\n" +
            "driverPhone 电话\n" +
            "vco 字符串类型 1：蓝色；2：黄色\n" +
            "lon 经度\n" +
            "lat 纬度\n" +
            "adr 车辆位置\n" +
            "spd 速度 km/h\n" +
            "province 省\n" +
            "country 区\n" +
            "city 市\n" +
            "drc 方向 字符串类型（0 或 360：正北， 大于 0 且小于 90：东北，等于\n" +
            "\t 90：正东，大于 90 且小于 180： 东南，等于 180：正南，大于 180 且小于 270：西南，等于\n" +
            "\t 270：正西，大于 270 且小于等 于 359：西北，其他：未知）\n" +
            "utc; 时间\n" +
            "type 状态\n" +
            "",httpMethod = "POST")
    public JsonResult listPage(PageResult2 page, CarPosition carPosition, HttpServletRequest request)  throws Exception{
        return carPositionService.listPage(page,carPosition);
    }

    /**
     * 所有地图模块
     */
    @PreAuthorize("hasAuthority('gps:gps:list')")
    @PostMapping("/listAll")
    @ApiOperation(value = "所有地图模块",notes = "" +
            "vno: 车牌 浙Be2343\n"+
            "date1: 时间 只能传一天会卡死\n"+
            "date2: 时间 只能传一天会卡死\n"+
            "",httpMethod = "POST")
    public JsonResult listAll( CarPosition carPosition, HttpServletRequest request)  throws Exception{
        return carPositionService.list(carPosition);
    }

    /**
     * 所有地图模块  所有车辆 但是要钱
     */
    @PreAuthorize("hasAuthority('gps:gps:list')")
    @PostMapping("/trajectory")
    @ApiOperation(value = "中交兴路的gps  所有车辆 但是要钱",notes = "" +
            "vno: 车牌 浙Be2343\n"+
            "date1: 时间\n"+
            "date2: 时间\n"+
            "hgt: 海拔\n"+
            "mlg: 里程 单位：百米\n"+
            "",httpMethod = "POST")
    public JsonResult trajectory(CarPosition carPosition, HttpServletRequest request)  throws Exception{
        return carPositionService.trajectory(carPosition);
    }

    /**
     * 所有地图模块
     */
    @PreAuthorize("hasAuthority('gps:gps:list')")
    @PostMapping("/normalCarList")
    @ApiOperation(value = "常用的8辆车子出行状态",notes = "" +
            "vno: 常用的8辆车子 浙Be2343,浙Be2342\n"+
            "",httpMethod = "POST")
    public JsonResult normalCarList(CarPosition carPosition, HttpServletRequest request)  throws Exception{
        return carPositionService.normalCarList(carPosition);
    }

    /**
     * 所有地图模块
     */
    @PreAuthorize("hasAuthority('gps:gps:list')")
    @PostMapping("/syncList")
    @ApiOperation(value = "实时车辆的gps",notes = "" +
            "billId: 订单id\n"+
            "customer: 根据客户的名称 查询车辆\n"+
            "vno: 根据车牌\n"+
            "factoryAddress: 工厂地址\n"+
            "state: 状态\n"+
            "dock: 港口\n"+
            "dockLongitude: 港口经度\n"+
            "dockLatitude: 港口纬度\n"+
            "up_yard: 堆场\n"+
            "upyardLongitude: 堆场经度\n"+
            "upyardLatitude: 堆场纬度\n"+
            "",httpMethod = "POST")
    public JsonResult syncList(CarPosition carPosition, HttpServletRequest request)  throws Exception{
        return carPositionService.syncList(carPosition);
    }

    /**
     * 实时车辆的gps提醒并推送公众号
     */
    @PreAuthorize("hasAuthority('gps:gps:list')")
    @PostMapping("/syncListAndRemind")
    @ApiOperation(value = "实时车辆的gps提醒并推送公众号",notes = "" +
            "billId: 订单id\n"+
            "customer: 根据客户的名称 查询车辆\n"+
            "vno: 根据车牌\n"+
            "factoryAddress: 工厂地址\n"+
            "state: 状态\n"+
            "dock: 港口\n"+
            "dockLongitude: 港口经度\n"+
            "dockLatitude: 港口纬度\n"+
            "up_yard: 堆场\n"+
            "upyardLongitude: 堆场经度\n"+
            "upyardLatitude: 堆场纬度\n"+
            "packDate 装箱时间\n"+
            "distance: 离工厂距离\n"+
            "duration: 到工厂时间\n"+
            "warn: 警告  1 约定时间超过1小时还到不了的,  2 没有提到箱子 0 正常\n"+
            "",httpMethod = "POST")
    public JsonResult syncListAndRemind(CarPosition carPosition, HttpServletRequest request)  throws Exception{
        return carPositionService.syncListAndRemind(carPosition);
    }

    /**
     * 实时位置  指定账号查询所有车辆(要收费的)
     */
    @PreAuthorize("hasAuthority('gps:gps:list')")
    @PostMapping("/carPosition")
    @ApiOperation(value = "实时位置  指定账号查询所有车辆(要收费的)",notes = "" +
            "vno: 根据车牌\n"+
            "",httpMethod = "POST")
    public JsonResult carPosition(String vno, HttpServletRequest request)  throws Exception{
        return ZjxlGps.vLastLocationV4_origin(vno);
    }

    /**
     * 所有地图模块
     */
    @PreAuthorize("hasAuthority('gps:gps:list')")
    @PostMapping("/historyList")
    @ApiOperation(value = "历史车辆的gps",notes = "" +
            "billId 订单id"+
            "",httpMethod = "POST")
    public JsonResult historyList(CarPosition carPosition, HttpServletRequest request)  throws Exception{
        return carPositionService.historyList(carPosition);
    }

    /**
     * 所有地图模块
     */
//    @PreAuthorize("hasAuthority('gps:gps:list')")
//    @PostMapping("/historyListOriginal")
//    @ApiOperation(value = "历史车辆的gps原数据 没在用",notes = "" +
//            "billId 订单id"+
//            "",httpMethod = "POST")
    public JsonResult historyListOriginal(CarPosition carPosition, HttpServletRequest request)  throws Exception{
        return carPositionService.historyListOriginal(carPosition);
    }

    /**
     * 所有地图模块
     */
    @PreAuthorize("hasAuthority('gps:gps:list')")
    @PostMapping("/checkTruckExist")
    @ApiOperation(value = "车辆是否入网",notes = "" +
            "vno 车牌"+
            "",httpMethod = "POST")
    public JsonResult checkTruckExist(CarPosition carPosition, HttpServletRequest request)  throws Exception{
        return carPositionService.checkTruckExist(carPosition);
    }

    /**
     * 所有地图模块
     */
    @PreAuthorize("hasAuthority('gps:gps:list')")
    @PostMapping("/checkVehicleExist")
    @ApiOperation(value = "先判断是否是入网车辆并返回车机的最后在线时间",notes = "" +
            "vno 车牌"+
            "",httpMethod = "POST")
    public JsonResult checkVehicleExist(CarPosition carPosition, HttpServletRequest request)  throws Exception{
        return carPositionService.checkVehicleExist(carPosition);
    }

    /**
     * 所有地图模块
     */
    @PreAuthorize("hasAuthority('gps:gps:list')")
    @PostMapping("/singleGps")
    @ApiOperation(value = "历史车辆的gps",notes = "" +
            "vno 车牌 浙BJ8510_2"+
            "",httpMethod = "POST")
    public JsonResult singleGps(CarPosition carPosition, HttpServletRequest request)  throws Exception{
        return JsonResult.ok().setData(ZjxlGps.vLastLocationV3(carPosition.getVno()));
    }

    /**
     * 关键字的补完与提示
     */
    @PreAuthorize("hasAuthority('gps:gps:list')")
    @PostMapping("/txMapSuggestion")
    @ApiOperation(value = "腾讯地图关键字的补完与提示",notes = "" +
            "keyword 关键字"+
            "",httpMethod = "POST")
    public JsonResult suggestion(String keyword, HttpServletRequest request)  throws Exception{
        return carPositionService.suggestion(keyword);
    }

    /**
     * 添加地图模块
     */
    @PreAuthorize("hasAuthority('gps:gps:list')")
    @PostMapping("/findById")
    @ApiOperation(value = "添加地图模块",notes = "" +
            "id; id\n" +
            "",httpMethod = "POST")
    public JsonResult findById(CarPosition carPosition, HttpServletRequest request)  throws Exception{
        return carPositionService.findById(carPosition);
    }

    /**
     * 修改地图模块
     */
    @PreAuthorize("hasAuthority('gps:gps:save')")
    @PostMapping("/save")
    @ApiOperation(value = "修改地图模块",notes = "" +
            "id; id\n" +
            "carNo 车牌\n" +
            "lon 经度\n" +
            "lat 纬度\n" +
            "spd 速度 km/h\n" +
            "province 省\n" +
            "city 市\n" +
            "country 县\n" +
            "drc 方向 字符串类型（0 或 360：正北， 大于 0 且小于 90：东北，等于\n" +
            "\t 90：正东，大于 90 且小于 180： 东南，等于 180：正南，大于 180 且小于 270：西南，等于\n" +
            "\t 270：正西，大于 270 且小于等 于 359：西北，其他：未知）\n" +
            "utc; 时间" +
            "",httpMethod = "POST")
    public JsonResult save( CarPosition carPosition, HttpServletRequest request)  throws Exception{
        return carPositionService.save(carPosition);
    }

    /**
     * 修改地图模块
     */
    @PreAuthorize("hasAuthority('gps:gps:update')")
    @PostMapping("/update")
    @ApiOperation(value = "修改地图模块",notes = "" +
            "",httpMethod = "POST")
    public JsonResult update( CarPosition carPosition, HttpServletRequest request)  throws Exception{
        return carPositionService.update(carPosition);
    }

    /**
     * 删除地图模块
     */
    @PreAuthorize("hasAuthority('gps:gps:remove')")
    @PostMapping("/remove")
    @ApiOperation(value = "删除地图模块",notes = "" +
            "",httpMethod = "POST")
    public JsonResult remove( CarPosition carPosition, HttpServletRequest request)  throws Exception{
        return carPositionService.remove(carPosition);
    }


}
